home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Cursor;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLEncoder;
-
- public class Memory extends Applet implements Runnable, MouseListener, MouseMotionListener {
- private Thread thread;
- private Image buffer;
- private Image backImage;
- private Image[] image;
- private Image turnedImage;
- // $FF: renamed from: b java.awt.Graphics
- private Graphics field_0;
- private boolean loaded;
- private int wiBack;
- private int heBack;
- private boolean isBackImage = false;
- // $FF: renamed from: N int
- private int field_1 = 1;
- // $FF: renamed from: wi int
- private int field_2;
- // $FF: renamed from: he int
- private int field_3;
- private int wiIm;
- private int heIm;
- private int pause = 50;
- private int NCol = 1;
- private int NRow;
- private String[] image_string;
- private String backImageName;
- private Color backColor;
- private String statusBarText;
- private AudioClip sound;
- private AudioClip clicSound;
- private AudioClip enterSound;
- private boolean loopSound;
- private String link;
- private Color turnedColor;
- private int[][] mat;
- private int[][] ret;
- private int wiSpace;
- private int heSpace;
- private boolean hand = false;
- private int lastClic;
- private int iLast;
- private int jLast;
- private boolean change;
- // $FF: renamed from: I int
- private int field_4;
- // $FF: renamed from: J int
- private int field_5;
-
- public String getAppletInfo() {
- return "Name: Memory\r\nAuthor: Taiji Software\r\n";
- }
-
- public Memory() {
- this.turnedColor = Color.black;
- ((Component)this).addMouseListener(this);
- ((Component)this).addMouseMotionListener(this);
- }
-
- public void register() {
- try {
- URL u = new URL("http://www.taijisoftware.com");
- ((Applet)this).getAppletContext().showDocument(u, "_blank");
- } catch (Exception e) {
- System.out.println(e);
- this.stop();
- }
- }
-
- public void init() {
- String codeBase = null;
-
- try {
- codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
- System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
- codeBase = codeBase.toUpperCase();
- } catch (Exception var11) {
- }
-
- if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
- String regCode = ((Applet)this).getParameter("registration_code");
- if (regCode == null) {
- regCode = ((Applet)this).getParameter("reg_domain");
- if (regCode == null) {
- this.register();
- } else {
- if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
- codeBase = "WWW." + codeBase;
- } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
- codeBase = codeBase.substring(4);
- }
-
- char[] chars = new char[codeBase.length()];
- codeBase.getChars(0, codeBase.length(), chars, 0);
- String key = new String("haricot");
- char[] chars2 = new char[key.length()];
- key.getChars(0, key.length(), chars2, 0);
-
- for(int i = 0; i < codeBase.length(); ++i) {
- int j;
- if (i >= key.length()) {
- j = i - key.length() * (i / key.length());
- } else {
- j = i;
- }
-
- chars[i] += chars2[j];
- chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
- }
-
- String res = new String(chars);
- if (!res.equalsIgnoreCase(regCode)) {
- this.register();
- }
- }
- } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
- this.register();
- }
- }
-
- this.getParameters();
- this.NRow = (int)((float)(2 * this.field_1) / (float)this.NCol);
- if (2 * this.field_1 % this.NCol != 0) {
- ++this.NRow;
- }
-
- this.mat = new int[this.NRow][this.NCol];
- this.ret = new int[this.NRow][this.NCol];
- int n = 1;
- int c = 0;
-
- for(int i = 0; i < this.NRow; ++i) {
- for(int j = 0; j < this.NCol; ++j) {
- this.ret[i][j] = 0;
- if (n == this.field_1 + 1) {
- this.mat[i][j] = 0;
- } else {
- this.mat[i][j] = n;
- if (c == 1) {
- ++n;
- }
-
- c = 1 - c;
- }
- }
- }
-
- for(int k = 0; k < 500; ++k) {
- int i1 = (int)(Math.random() * (double)this.NRow);
- int j1 = (int)(Math.random() * (double)this.NCol);
- int i2 = (int)(Math.random() * (double)this.NRow);
- int j2 = (int)(Math.random() * (double)this.NCol);
- if (this.mat[i1][j1] != 0 && this.mat[i2][j2] != 0) {
- int b = this.mat[i1][j1];
- this.mat[i1][j1] = this.mat[i2][j2];
- this.mat[i2][j2] = b;
- } else {
- --k;
- }
- }
-
- if (this.sound != null) {
- if (this.loopSound) {
- this.sound.loop();
- return;
- }
-
- this.sound.play();
- }
-
- }
-
- public void getParameters() {
- this.field_2 = ((Component)this).getSize().width;
- this.field_3 = ((Component)this).getSize().height;
-
- for(this.field_1 = 0; ((Applet)this).getParameter("image" + Integer.toString(this.field_1 + 1)) != null; ++this.field_1) {
- }
-
- this.image_string = new String[this.field_1];
-
- for(int i = 0; i < this.field_1; ++i) {
- this.image_string[i] = ((Applet)this).getParameter("image" + Integer.toString(i + 1));
- }
-
- String s = ((Applet)this).getParameter("pause");
- if (s != null) {
- this.pause = Integer.parseInt(s);
- }
-
- s = ((Applet)this).getParameter("columns_number");
- if (s != null) {
- this.NCol = Integer.parseInt(s);
- }
-
- if (((Applet)this).getParameter("turned_color") != null) {
- this.turnedColor = this.getColor("turned_color");
- }
-
- this.backImageName = ((Applet)this).getParameter("background_image");
- if (this.backImageName != null) {
- this.isBackImage = true;
- }
-
- ((Component)this).setBackground(this.getColor("background_color"));
- this.statusBarText = ((Applet)this).getParameter("status_bar_text");
- s = ((Applet)this).getParameter("sound_name");
- if (s != null) {
- this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
- }
-
- s = ((Applet)this).getParameter("loop_sound");
- if (s != null) {
- if (s.equals("yes")) {
- this.loopSound = true;
- } else {
- this.loopSound = false;
- }
- }
-
- s = ((Applet)this).getParameter("clic_sound_name");
- if (s != null) {
- this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
- }
-
- this.link = ((Applet)this).getParameter("link");
- }
-
- public Color getColor(String param) {
- String s = ((Applet)this).getParameter(param);
- if (s != null) {
- if (s.substring(0, 1).equals("#")) {
- s = s.substring(1);
- int i = Integer.parseInt(s, 16);
- return new Color(i);
- } else {
- return null;
- }
- } else {
- return null;
- }
- }
-
- public final void paint(Graphics g) {
- if (this.loaded) {
- this.field_0.clearRect(0, 0, this.field_2, this.field_3);
- if (this.isBackImage) {
- this.field_0.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
- }
-
- for(int i = 0; i < this.NRow; ++i) {
- for(int j = 0; j < this.NCol; ++j) {
- if (this.mat[i][j] != 0) {
- if (this.ret[i][j] == 0) {
- if (this.turnedImage != null) {
- this.field_0.drawImage(this.turnedImage, this.wiSpace + j * (this.wiSpace + this.wiIm), this.heSpace + i * (this.heSpace + this.heIm), this.wiIm, this.heIm, this);
- } else {
- this.field_0.fillRect(this.wiSpace + j * (this.wiSpace + this.wiIm), this.heSpace + i * (this.heSpace + this.heIm), this.wiIm, this.heIm);
- }
- } else {
- this.field_0.drawImage(this.image[this.mat[i][j] - 1], this.wiSpace + j * (this.wiSpace + this.wiIm), this.heSpace + i * (this.heSpace + this.heIm), this.wiIm, this.heIm, this);
- }
- }
- }
- }
-
- g.drawImage(this.buffer, 0, 0, this);
- if (this.change) {
- this.sleep(1000);
- this.ret[this.iLast][this.jLast] = 0;
- this.ret[this.field_4][this.field_5] = 0;
- this.lastClic = 0;
- this.change = false;
- }
- }
-
- }
-
- public final void update(Graphics g) {
- this.paint(g);
- }
-
- public void start() {
- if (this.thread == null) {
- this.thread = new Thread(this);
- this.thread.start();
- }
-
- }
-
- public void stop() {
- if (this.thread != null) {
- this.thread = null;
- }
-
- if (this.sound != null) {
- this.sound.stop();
- }
-
- }
-
- public void run() {
- if (!this.loaded) {
- this.image = new Image[this.field_1];
- MediaTracker tracker = new MediaTracker(this);
-
- for(int i = 0; i < this.field_1; ++i) {
- this.image[i] = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image_string[i]);
- }
-
- for(int i = 0; i < this.field_1; ++i) {
- tracker.addImage(this.image[i], 0);
- }
-
- if (this.isBackImage) {
- this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
- tracker.addImage(this.backImage, 0);
- }
-
- if (((Applet)this).getParameter("turned_image") != null) {
- this.turnedImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("turned_image"));
- tracker.addImage(this.turnedImage, 0);
- }
-
- try {
- tracker.waitForAll();
- this.loaded = !tracker.isErrorAny();
- } catch (Exception e) {
- System.out.println(e);
- }
-
- if (!this.loaded) {
- this.stop();
- }
- }
-
- this.wiIm = this.field_2;
- this.heIm = this.field_3;
-
- for(int i = 0; i < this.field_1; ++i) {
- if (this.image[i].getWidth(this) < this.wiIm) {
- this.wiIm = this.image[i].getWidth(this);
- }
-
- if (this.image[i].getHeight(this) < this.heIm) {
- this.heIm = this.image[i].getHeight(this);
- }
- }
-
- this.wiSpace = (int)((float)(this.field_2 - this.NCol * this.wiIm) / (float)(this.NCol + 1));
- this.heSpace = (int)((float)(this.field_3 - this.NRow * this.heIm) / (float)(this.NRow + 1));
- this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
- this.field_0 = this.buffer.getGraphics();
- this.field_0.setColor(this.turnedColor);
- if (this.isBackImage) {
- this.wiBack = this.backImage.getWidth(this);
- this.heBack = this.backImage.getHeight(this);
- }
-
- while(true) {
- ((Component)this).repaint();
- this.sleep(this.pause);
- }
- }
-
- public void sleep(int pause) {
- try {
- Thread.sleep((long)pause);
- } catch (InterruptedException var2) {
- this.stop();
- }
- }
-
- public URL giveURL(String url) {
- try {
- if (url.toUpperCase().startsWith("HTTP")) {
- return new URL(url);
- } else if (url.toUpperCase().startsWith("FTP")) {
- int p = url.indexOf(":");
- int p2 = url.indexOf(":", p + 1);
- if (p2 != -1) {
- url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
- }
-
- p = url.indexOf("%40");
- if (p != -1) {
- url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
- }
-
- return new URL(url);
- } else {
- return new URL(((Applet)this).getCodeBase(), url);
- }
- } catch (MalformedURLException e) {
- System.out.println(e);
- return null;
- }
- }
-
- public void mouseClicked(MouseEvent e) {
- if (this.clicSound != null) {
- this.clicSound.play();
- }
-
- int x = e.getX();
- int y = e.getY();
-
- for(int i = 0; i < this.NRow; ++i) {
- for(int j = 0; j < this.NCol; ++j) {
- if (x >= this.wiSpace + j * (this.wiSpace + this.wiIm) && x <= (j + 1) * (this.wiSpace + this.wiIm) && y >= this.heSpace + i * (this.heSpace + this.heIm) && y <= (i + 1) * (this.heSpace + this.heIm)) {
- if (this.mat[i][j] == 0) {
- return;
- }
-
- if (this.ret[i][j] == 0) {
- this.ret[i][j] = 1;
- if (this.lastClic == 0) {
- this.lastClic = this.mat[i][j];
- this.iLast = i;
- this.jLast = j;
- return;
- }
-
- if (this.lastClic != this.mat[i][j]) {
- this.change = true;
- this.field_4 = i;
- this.field_5 = j;
- ((Component)this).repaint();
- return;
- }
-
- this.lastClic = 0;
- boolean flag = false;
-
- for(int ii = 0; ii < this.NRow; ++ii) {
- for(int jj = 0; jj < this.NCol; ++jj) {
- if (this.ret[ii][jj] == 0 && this.mat[ii][jj] != 0) {
- flag = true;
- }
- }
- }
-
- if (!flag && this.link != null) {
- String target = ((Applet)this).getParameter("target");
- if (target == null) {
- target = "_blank";
- }
-
- URL u = this.giveURL(this.link);
- ((Applet)this).getAppletContext().showDocument(u, target);
- }
- }
-
- return;
- }
- }
- }
-
- }
-
- public void mouseEntered(MouseEvent e) {
- if (this.statusBarText != null) {
- ((Applet)this).showStatus(this.statusBarText);
- }
-
- }
-
- public void mouseExited(MouseEvent e) {
- }
-
- public void mousePressed(MouseEvent e) {
- }
-
- public void mouseReleased(MouseEvent e) {
- }
-
- public void mouseDragged(MouseEvent e) {
- }
-
- public void mouseMoved(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
-
- for(int i = 0; i < this.NRow; ++i) {
- for(int j = 0; j < this.NCol; ++j) {
- if (x >= this.wiSpace + j * (this.wiSpace + this.wiIm) && x <= (j + 1) * (this.wiSpace + this.wiIm) && y >= this.heSpace + i * (this.heSpace + this.heIm) && y <= (i + 1) * (this.heSpace + this.heIm)) {
- if (this.mat[i][j] == 0) {
- return;
- }
-
- if (!this.hand) {
- ((Component)this).setCursor(new Cursor(0));
- this.hand = true;
- }
-
- return;
- }
- }
- }
-
- if (this.hand) {
- ((Component)this).setCursor(new Cursor(0));
- this.hand = false;
- }
-
- }
- }
-